package ex;

import java.util.Random;
import java.util.Scanner;

/**
 * @author wzby
 * @Date: 2022/8/8 8:49
 */
public class Ex1 {
    public static void main(String[] args) {
        System.out.println("===猜数游戏===");

        Random rand = new Random();
        var sc = new Scanner(System.in);
        int r = rand.nextInt(1,101);
        System.out.println("输入数字：");
        while (true) {

            int i = 0;

            if (sc.hasNextInt()) {
                i = sc.nextInt();
            } else {
                sc.nextLine();
                System.out.println("输入错误，请继续输入");
                continue;
            }
            if ( i == r) {
                System.out.println("猜对了");
                break;
            } else if (i < r){
                System.out.println("小于数字");
            }else if (i > r){
                System.out.println("大于数字");
            }else {
                System.out.println("猜错了");
            }
        }
    }
}
